# src/models/sys_objects.py
from sqlalchemy import Column, String, DateTime, Boolean, Integer, Index
from src.core.ormdb import Base
from src.core import str_utils as strU


class SysObjects(Base):
    __tablename__ = "sys_objects"
    __table_args__ = {"comment": "对象资料表"}

    id = Column(String(36), primary_key=True, default=lambda: strU.generate_id(), comment="ID")
    api_id = Column(String(36), nullable=False, index=True, comment="API主键，用于关联其他系统")
    object_name = Column(String(64), comment="对象名称")
    alias = Column(String(64), comment="对象别名")
    description = Column(String(128), comment="对象说明")
    object_type = Column(String(64), comment="T:表 V:视图 P:存储过程 FT:函数表 FC:函数值")
    cols_per_row = Column(Integer, default=1, comment="每行列数")
    inner_object = Column(String(64), comment="关联对象")
    inner_id = Column(String(36), comment="关联对象号码")
    sort = Column(Integer, default=10, comment="排序")
    enabled = Column(Boolean, default=True, comment="可用")

    # 软删除
    deletion_mark = Column(Boolean, default=False, comment="删除标志，0表示未删除，1表示已删除")
    deletion_reason = Column(String(255), nullable=True, comment="删除原因，记录删除的具体原因")
    deletion_date = Column(DateTime, nullable=True, comment="删除日期，记录删除的时间")
    deletion_by = Column(String(255), nullable=True, comment="删除者，记录删除操作的执行者")

    # 审计
    create_date = Column(DateTime, default=lambda: strU.now(), comment="创建日期，记录创建的时间")
    creator_by = Column(String(255), comment="创建者")
    last_updated_date = Column(DateTime, nullable=True, comment="最后更新时间，记录最后更新的时间")
    last_updated_by = Column(String(255), comment="最后更新者")


